<template>
  <common-table
    :fetch="getDataAsync"
    :fetch-params="apiParams"
    :columns="columnsList"
    ref="table"
    :show-toolbar="false"
    @vue:mounted="() => $refs.table.load()"
    style="width: 100%; height: 100%"
    :scroll="{ x: data.age < 18 ? 1200 : 'auto' }"
  >
    <template #index="{ index }">
      <span>{{ index + 1 }}</span>
    </template>
  </common-table>
</template>

<script>
import CommonTable from '@gis/lib/components/vex-table/index.vue';
import concat from 'lodash-es/concat.js';
import { getEnumText } from '@gis/lib/enums/index.js';

export default {
  name: 'net-room-live-info',
  components: { CommonTable },
  props: {
    data: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      columns: [
        {
          title: '网约房名称',
          dataIndex: 'hotel_name',
        },
        {
          title: '房间全名称',
          dataIndex: 'room_full_name',
        },
        {
          title: '登记来源',
          dataIndex: 'source',
          customRender: (val) => getEnumText('registerSource', val),
        },
        {
          title: '入住时间',
          dataIndex: 'create_time',
        },
        {
          title: '预离时间',
          dataIndex: 'end_time',
        },
      ],
    };
  },
  computed: {
    columnsList() {
      return this.data.age < 18
        ? concat(this.columns, [
            {
              title: '监护人姓名',
              dataIndex: 'guardian_name',
              ellipsis: true,
              width: 110,
            },
            {
              title: '监护人联系电话',
              dataIndex: 'guardian_phone',
              ellipsis: true,
              width: 130,
            },
            {
              title: '监护人身份证号',
              dataIndex: 'guardian_id_card',
              ellipsis: true,
              width: 150,
            },
            {
              title: '监护人关系',
              dataIndex: 'relation',
              ellipsis: true,
              width: 110,
            },
          ])
        : this.columns;
    },
    apiParams() {
      return {
        people_id: this.data.people_id,
        all: 'all',
      };
    },
  },
  methods: {
    async getDataAsync(params) {
      const res = await this.$axios.get('/xw-microservice/xw-hotel/v3/hotel/room/people/history/page', { params });
      const data = res.data || {};
      return { data: data.list, total: data.count };
    },
  },
};
</script>

<style scoped></style>
